import React from "react";
import {Consumer} from "../../theme";
import './index.less';
import {WeaLocaleProvider} from "ecCom";

const getLabel = WeaLocaleProvider.getLabel;

export default class FBHeaderView extends React.Component {
    render() {
        const {bottom, shortkey, data, ...props} = this.props;

        if (bottom) {
            return (
                data.footerDesc ?
                  <div
                    {...props}
                    className='wev-edc-form-bottom__view'
                  >
                    {data.footerDesc && <p className='fbottom-desc' dangerouslySetInnerHTML={{__html: data.footerDesc}}/>}
                    {shortkey && <a style={{float: 'right', paddingRight: '10px', textDecoration: 'underline'}} href={`/mobilemode/showdata.jsp?key=${shortkey}`}>{getLabel('502636','查看数据')}</a>}
                  </div>
                  :null
            )
        } else {
            return (
                <Consumer>
                    {({header, title}) => (
                        <div
                            {...props}
                            className='wev-edc-form-header__view'
                        >
                          {
                            header.visible ?
                              (
                                header.type == 0 ?
                                  <div className='fheader-banner' style={header.css}><span>{header.text}</span></div>
                                  :
                                <div className='fheader-banner-img' style={{backgroundColor: header.css.backgroundColor, textAlign: header.css.textAlign, fontSize: '0'}}><img src={header.img}/></div>
                              )
                              : null
                          }
                            {data.title && <p className='fheader-title' style={title.css}>{data.title}</p>}
                            {data.desc && <p className='fheader-desc' dangerouslySetInnerHTML={{__html: data.desc}}/>}
                        </div>
                    )}
                </Consumer>
            );
        }
    }
}

FBHeaderView.defaultProps = {
    data: {
        title: getLabel('502504', '新的表单'),
        desc: ''
    }
};